home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17686 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: seas.smu.edu!not-for-mail
  2. From: dbowman@post.smu.edu (Damon Bowman)
  3. Newsgroups: comp.lang.c++
  4. Subject: How to Get all Permutations
  5. Date: 16 Apr 1996 20:02:34 -0500
  6. Organization: Southern Methodist University - Bradfied Computer Center - Dallas
  7. Sender: usenet@seas.smu.edu
  8. Message-ID: <3174417f.15405235@sun.cis.smu.edu>
  9. NNTP-Posting-Host: sun.cis.smu.edu
  10. X-Nntp-Posting-Host: ax4-6.ppp.smu.edu
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. I'm writing a program in which I need to fill an array with all
  14. possible combinations of a group of numbers.
  15.  
  16. For example, say you have the following table:
  17.  Choices - A  B  C
  18. -------------------
  19. Person 1 - 1  2  3
  20. Person 2 - 2  3  1
  21. Person 3 - 3  1  2
  22.  
  23. This is one possible combination out of 216 (#choices!)^#persons =
  24. 3!^3 = 216.
  25.  
  26. In other words, each person must rank three choices in order of
  27. preference.  I am trying to fill an array with every possible
  28. combination of all three persons' choices.
  29.  
  30. The array would be structured: array[3][3][216], or:
  31. array[persons][choices][choices!^persons]
  32.  
  33. I realize I am using math symbols, not C++ syntax, to explain my
  34. problem. I already have factorial and exponentiation functions to use.
  35.  
  36. The rest of the program involves determining how many of the possible
  37. combinations result in a particular circular paradox whereby A is
  38. preferred to B, B is preferred to C, yet C is preferred to A.  The
  39. paradox also occurs in reverse, whereby C is preferred to B, B is
  40. preferred to A, and A is preferred to C.  The table above is an
  41. example of an occurence of this paradox.
  42.  
  43. I have already figured out how to uncover all the cases containing the
  44. paradox, but can't quite get the array filled with all the possible
  45. combinations.
  46.  
  47. I am also trying to write the program so that the number of choices
  48. and the number of persons is variable.  In other words, I'm designing
  49. the program to work for tables of varying size, but for now I'm using
  50. integer data types.  Still, it should work for 3, 4, 5, etc. persons,
  51. and I can upgrade the data types to a user defined type later that can
  52. hold larger numbers.
  53.  
  54. Any help would be appreciated.  By the way, this is not a school
  55. assignment, but rather a job for a professor teaching a class I'm not
  56. currently taking.
  57.